package com.tentative.competition.common.utils;

import com.tentative.competition.common.constant.Constants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class WebUtils {

    /**
     * Get request
     *
     * @return the request
     */
    public static HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    /**
     * To Simple Token
     *
     * @param token
     * @return
     */
    public static String toSimpleToken(String token) {
        return token != null && token.startsWith(Constants.TOKEN_PREFIX) ? StringUtils.substringAfter(token, Constants.TOKEN_PREFIX) : token;
    }

}
